--create table test (msg varchar2(256), time timestamp default systimestamp);

set serveroutput on

create or replace procedure my_scheduler_job_proc( caller IN varchar2)
is
	l_sid pls_integer;
	l_counter pls_integer := 0;
	l_conn utl_tcp.connection;
begin
	while true
	loop
		select sys_context('USERENV', 'SID') into l_sid from dual;
		--insert into test (msg) values ( '[' || l_counter || '] Session ID: ' || l_sid || '~' || caller);
		--commit;
		l_conn := utl_tcp.open_connection('192.168.1.1', 80);
		l_counter := l_counter + 1;
		--dbms_lock.sleep(3);
	end loop;
exception
	when others then
		insert into test (msg) values ( 'sid:' || l_sid || ', max open:'|| l_counter );
		commit;
		utl_tcp.close_all_connections();
end;
/
show err;



DECLARE
  l_job_name varchar2(256);
  l_sid pls_integer;
  l_conn utl_tcp.connection;
BEGIN
	select sys_context('USERENV', 'SID') into l_sid from dual;
	l_conn := utl_tcp.open_connection('192.168.1.1', 80);
	
	DBMS_SCHEDULER.create_job (
		job_name => 'Scheduler_job_djt',
		job_type => 'STORED_PROCEDURE',
		job_action=> 'my_scheduler_job_proc',
		number_of_arguments=> 1,
		start_date=> sysdate,
		repeat_interval=> null, --'FREQ=SECONDLY;',
		enabled=>false,
		auto_drop=>true,
		comments=>'a test scheduler job' );

	dbms_scheduler.set_job_argument_value(
        job_name => 'Scheduler_job_djt'
      , argument_position => 1
      , argument_value => 'James');
      
      dbms_scheduler.enable('Scheduler_job_djt');
   dbms_output.put_line('Current Session ID: ' || l_sid );

END;
/